package Comparador;
import java.util.Comparator;

public class Tester {
	
	public static void comparar_personas_comparables() {
		System.out.println("-------------------------------------------------------");
		System.out.println("Comparando personas comparables");
		System.out.println("-------------------------------------------------------");
		
		PersonaComparable p1 = new PersonaComparable(1, "Ana", "Lopez");
		PersonaComparable p2 = new PersonaComparable(1, "Juan", "Alves");
		System.out.println("p1: "+p1.toString() + " \np2: "+ p2.toString());
		System.out.println("Resultado p1.compareTo(p2): " + p1.compareTo(p2) + "\n");
		
		p1 = new PersonaComparable(1, "Ana", "Lopez");
		p2 = new PersonaComparable(11, "Juan", "Alves");
		System.out.println("p1: "+p1.toString() + " \np2: "+ p2.toString());
		System.out.println("Resultado p1.compareTo(p2): " + p1.compareTo(p2) + "\n");
		
		p1 = new PersonaComparable(11, "Ana", "Lopez");
		p2 = new PersonaComparable(1, "Juan", "Alves");
		System.out.println("p1: "+p1.toString() + " \np2: "+ p2.toString());
		System.out.println("Resultado p1.compareTo(p2): " + p1.compareTo(p2) + "\n");
		
		System.out.println("------------------------------------------------------------------------\n");
	}
	
	public static void comparar_personas_con_comparador(String msj, Comparator<Persona> c) {
		System.out.println("-------------------------------------------------------");
		System.out.println(msj);
		System.out.println("-------------------------------------------------------");
		
		Persona p1 = new Persona(1, "Ana", "Lopez");
		Persona p2 = new Persona(1, "Juan", "Lopez");
		System.out.println("p1: "+p1.toString() + " \np2: "+ p2.toString());
		System.out.println("Resultado c.compare(p1,p2): " + c.compare(p1,p2) + "\n");
		
		p1 = new Persona(1, "Ana", "Lopez");
		p2 = new Persona(11, "Juan", "White");
		System.out.println("p1: "+p1.toString() + " \np2: "+ p2.toString());
		System.out.println("Resultado c.compare(p1,p2): " + c.compare(p1,p2) + "\n");
		
		p1 = new Persona(11, "Ana", "Lopez");
		p2 = new Persona(1, "Juan", "Alves");
		System.out.println("p1: "+p1.toString() + " \np2: "+ p2.toString());
		System.out.println("Resultado c.compare(p1,p2): " + c.compare(p1,p2) + "\n");
		
		System.out.println("------------------------------------------------------------------------\n");
		
	}
	
	public static void comparar_personas_comparador_dni() {
		String msj = "Comparando personas con comparador por DNI";
		Comparator<Persona> c = new ComparadorPersonaPorDni();
		comparar_personas_con_comparador(msj,c);	
	}
	
	public static void comparar_personas_comparador_apellidos() {
		String msj = "Comparando personas con comparador por Apellidos";
		Comparator<Persona> c = new ComparadorPersonaPorApellidos();
		comparar_personas_con_comparador(msj,c);	
	}
	
	public static void comparar_personas_comparador_defecto() {
		System.out.println("-------------------------------------------------------");
		System.out.println("Comparando personas comparables con comparador por defecto");
		System.out.println("-------------------------------------------------------");
		
		Comparator<PersonaComparable> c = new DefaultComparator<PersonaComparable>();
		
		PersonaComparable p1 = new PersonaComparable(1, "Ana", "Lopez");
		PersonaComparable p2 = new PersonaComparable(1, "Juan", "Alves");
		System.out.println("p1: "+p1.toString() + " \np2: "+ p2.toString());
		System.out.println("Resultado c.compare(p1,p2): " + c.compare(p1,p2) + "\n");
		
		p1 = new PersonaComparable(1, "Ana", "Lopez");
		p2 = new PersonaComparable(11, "Juan", "Alves");
		System.out.println("p1: "+p1.toString() + " \np2: "+ p2.toString());
		System.out.println("Resultado c.compare(p1,p2): " + c.compare(p1,p2) + "\n");
		
		p1 = new PersonaComparable(11, "Ana", "Lopez");
		p2 = new PersonaComparable(1, "Juan", "Alves");
		System.out.println("p1: "+p1.toString() + " \np2: "+ p2.toString());
		System.out.println("Resultado c.compare(p1,p2): " + c.compare(p1,p2) + "\n");
		
		System.out.println("------------------------------------------------------------------------\n");
	}
	
	public static void main(String [] args) {
		comparar_personas_comparables();
		comparar_personas_comparador_dni();
		comparar_personas_comparador_apellidos();
		comparar_personas_comparador_defecto();
	}
}
